package jsyf.oa.web.crm;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.crm.CustomerVisitFacade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by wangmin on 2018/1/15.
 */
@Api(value = "客户拜访接口", description = "客户拜访接口")
@Controller
@RequestMapping("/customerVisit")
public class CustomerVisitController {
    @Resource
    private CustomerVisitFacade customerVisitFacade;

    @ApiOperation(value = "获取拜访状态", notes = "@returnValue（0：未签到；1：已签到）")
    @ApiImplicitParam(name = "jsonData", value = "{'userId':'人员id'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/getStateByUserId.json", method = RequestMethod.POST)
    public void getStateByUserId(HttpServletResponse response, @RequestBody String jsonData) {
        Integer id = customerVisitFacade.getStateByUserId(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id.toString()));
    }

    @ApiOperation(value = "获取面访人信息", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'userId':'人员id'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/getEntityByUserId.json", method = RequestMethod.POST)
    public void getEntityByUserId(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject id = customerVisitFacade.getEntityByUserId(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id));
    }

    @ApiOperation(value = "面访签到", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'customerName':'客户姓名','customerTel':'客户电话','weChat':'微信号','createUserId':'人员id','longitude':'经度','latitude':'纬度','address':'地址'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/signIn.json", method = RequestMethod.POST)
    public void signIn(HttpServletResponse response, @RequestBody String jsonData) {
        Integer id = customerVisitFacade.save(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id.toString()));
    }

    @ApiOperation(value = "面访签退", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'customerName':'客户姓名','customerTel':'客户电话','weChat':'微信号','createUserId':'人员id','leaveImg':'签退照片路径','longitude':'经度','latitude':'纬度','address':'地址'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/signOut.json", method = RequestMethod.POST)
    public void signOut(HttpServletResponse response, @RequestBody String jsonData) {
        Integer r = customerVisitFacade.updateEntity(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(r.toString()));
    }

    @ApiOperation(value = "添加电访客户信息", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'customerTel':'客户电话','createUserId':'人员id'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/addTelCustomerVisit.json", method = RequestMethod.POST)
    public void addTelCustomerVisit(HttpServletResponse response, @RequestBody String jsonData) {
        Integer r = customerVisitFacade.addCustomerVisit(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(r.toString()));
    }
}
